package com.pfzy.utildemo.activity.record.soundrecord.upload;

import android.content.Context;
import android.text.TextUtils;

import com.pfzy.utildemo.activity.record.soundrecord.upload.Dto.UploadAudioInfo;
import com.pfzy.utildemo.activity.record.soundrecord.upload.callback.SimpleAddUploadCallback;
import com.pfzy.utildemo.activity.record.soundrecord.upload.callback.SimpleResumeUploadCallback;
import com.pfzy.utildemo.activity.record.soundrecord.upload.qiniu.QiniuCenter;

//import com.pfzy.sdk.soundrecord.upload.callback.simple.SimpleAddUploadCallback;
//import com.pfzy.sdk.soundrecord.upload.callback.simple.SimpleResumeUploadCallback;
//import com.pfzy.sdk.soundrecord.upload.oss.AliOssCenter;

public class UpLoadManager {
    private static String mHost;

    private UpLoadManager() {
    }

    public static void init(Context context, String host) {
        if (context != null && !TextUtils.isEmpty(host)) {
            mHost = host;
        }
    }

    /**
     * 添加到上传
     *
     * @param info
     * @param callback
     */
    public static void addToUpload(UploadAudioInfo info, SimpleAddUploadCallback callback) {
        boolean isRight = checkIntegrityCheck(info);
        if (!isRight) {
            callback.onFailed(info, 4000, "");
        } else {
            QiniuCenter.getInstance().uploadFile(info, callback);
        }
    }

    /**
     * 重新上传
     */
    public static void resumeToUpload(UploadAudioInfo info, SimpleResumeUploadCallback callback) {
        boolean isRight = checkIntegrityCheck(info);
        if (!isRight) {
            callback.onFailed(info, 4000, "");
        } else {
            QiniuCenter.getInstance().uploadFile(info, callback);
        }
    }

    public static String getCapHost() {
        return mHost;
    }

    /**
     * 完整性检查
     */
    private static boolean checkIntegrityCheck(UploadAudioInfo info) {
        if (TextUtils.isEmpty(info.getRecordTimestamp())) {
            return false;
        }

        if (info.getFilePathList() == null || info.getFilePathList().size() == 0) {
            return false;
        }
        return true;
    }
}
